﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECS.Demos.Tetris.Systems;
using EntityComponentSystem.Framework;
using ECS.Demos.Tetris.Components;

namespace ECS.Demos.Tetris.Behavoirs
{

    public class DrawBlocksBehavior : Behavior<IRenderSystem>
    {
        public DrawBlocksBehavior() : base("rendersystem", "drawblock") { }

        protected override Action GetEntityBehavior(IRenderSystem system, GameEngine ge, int entity)
        {
            var collidable = ge.GetComponent(entity, "collidable");
            var size = ge.GetComponent(entity, "size");
            var position = ge.GetComponent(entity, "position");
            var texture = ge.GetComponent(entity, "texture");
            var color = ge.GetComponent(entity, "color");

            var blockshapehelper = new BlockShapeHelper(collidable, size["width"]);

            return new Action(() =>
            {
                int sx = position["x"];
                int sy = position["y"];
                int width = size["width"];
                int height = size["height"];
                var c = color.ToColorEx();

                for (var x = 0; x < width; x++)
                {
                    for (var y = 0; y < height; y++)
                    {
                        if (blockshapehelper[x, y] == 1)
                            system.DrawTexture(texture["name"], sx + x, sy + y, 1, 1, c);
                    }
                }
            });
        }
    }
}
